%{
/*
 *
 * lex input file for sub-pascal scanner
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "treestruct.hpp"
#include "y.tab.h"
int line_no = 1;

char input();
void commenteof();

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{

/* Line 1676 of yacc.c  */
#line 14 "pascal.y"

	int a_number;
	int a_boolean;
	char* a_variable;
	tree* a_tree;
	enum ast_ops an_op;



/* Line 1676 of yacc.c  */
#line 158 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif

%}
%%
integer|Boolean	{ yylval.a_variable = strdup(yytext); return(PRIMITIVE_TYPE); }
const		{ return(CONST); }
[0-9]+		{ yylval.a_number = atoi(yytext); return(CONST_INT); }
true		{ yylval.a_number = 1; return(CONST_BOOL); }
false		{ yylval.a_number = 0; return(CONST_BOOL); }
and		{ return(AND); }
or		{ return(OR); }
div		{ return(DIV); }
mod		{ return(MOD); }
array		{ return(ARRAY); }
Program		{ return(PROGRAM); }
type		{ return(TYPE); }
of		{ return(OF); }
record		{ return(RECORD); }
end		{ return(END); }
begin		{ return(PBEGIN); }
var		{ return(VAR); }
not		{ return(NOT); }
else		{ return(ELSE); }
if		{ return(IF); }
then		{ return(THEN); }
while		{ return(WHILE); }
do		{ return(DO); }
procedure	{ return(PROCEDURE); }
function	{ return(FUNCTION); }


[a-zA-Z]([a-zA-Z]|[0-9])* { yylval.a_variable = strdup(yytext); return(IDENTIFIER); }


","	{ return(COMMA); }
"."	{ return(DOT); }
";"	{ return(SEMICOLON); }
":"	{ return(COLON);}
"="	{ return(EQUAL); }
"-"	{ return(MINUS); }
"+"	{ return(PLUS); }
".."	{ return(DOTDOT); }
"["	{ return(LBRAC); }
"]"	{ return(RBRAC); }
"("	{ return(LPAREN); }
")"	{ return(RPAREN); }
"*"	{ return(STAR); }
":="	{ return(ASSIGNMENT); }
">="	{ return(GE); }
">"	{ return(GT); }
"<="	{ return(LE); }
"<"	{ return(LT); }
"<>"	{ return(NOTEQUAL); }



[ \t\f]    ;

\n	line_no++;

.	{ fprintf (stderr, "'%c' (0%o): illegal charcter at line %d\n", yytext[0], yytext[0], line_no); }

%%

void commenteof()
{
 fprintf (stderr, "unexpected EOF inside comment at line %d\n", line_no);
 exit (1);
}

int yywrap()
{
 return (1);
}



